package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
@CrossOrigin
public class LoginController {

    public boolean a=false;
    @Autowired
    @RequestMapping("/logins")
    public String Login(){
        return "login";
    }

    @RequestMapping("/login")
    public String login(HttpServletRequest request, HttpServletResponse response , Model m, HttpSession session)throws Exception{
        String name = request.getParameter("username");
        String password = request.getParameter("password");
        if("root".equals(name)&&"123".equals(password)){
            a=true;
            session.setAttribute("userName",name);
            m.addAttribute("name",name);
            return "main";
        }
        return "login";
    }
}
